Skip to content

build: enable CA2007 enforcement via nested src/.editorconfig#5230

Draft
jamescrosswell wants to merge 1 commit into
mainfrom
fix/issue-2308-ca2007
Draft

build: enable CA2007 enforcement via nested src/.editorconfig#5230
jamescrosswell wants to merge 1 commit into
mainfrom
fix/issue-2308-ca2007

Conversation

@jamescrosswell
Copy link
Copy Markdown
Collaborator

Summary

Move ConfigureAwait(false) enforcement (CA2007) from the legacy src/CodeAnalysis.ruleset to a nested src/.editorconfig.

The ruleset file no longer reliably enables CA2007 with current .NET SDKs (CA2007 is disabled by default in modern .NET analyzers, and <CodeAnalysisRuleSet> only overrides severity for rules that are already active). As a result, the rule only fired in CI Release builds and was silently ignored locally — both in Rider and with dotnet build — which is exactly the regression reported in #2308.

Using dotnet_diagnostic.CA2007.severity = error inside a nested editorconfig under /src has two advantages over the previous setup:

  • It correctly activates analyzer rules that are disabled by default, so violations now fail the build everywhere — locally and in CI, in Debug and Release.
  • It naturally scopes the rule to library code only. Tests, samples, benchmarks and integration-test projects are unaffected, where calling ConfigureAwait(false) is unnecessary noise.

Verification

Tested locally on macOS:

  • Clean build of src/Sentry/Sentry.csproj in Debug → 0 errors.
  • Temporarily replaced await sentryTask.ConfigureAwait(false); with await sentryTask; in SpotlightHttpTransport.cs → build fails with:
    error CA2007: Consider calling ConfigureAwait on the awaited task
    
    ...across all target frameworks (net8.0, net9.0, net10.0). Reverted before commit.
  • Built test/Sentry.Tests/Sentry.Tests.csproj with its existing await client.GetAsync(...); calls (no ConfigureAwait) → 0 CA2007 errors, confirming the rule is correctly scoped to /src only.

Closes #2308

#skip-changelog

Move ConfigureAwait(false) enforcement (CA2007) from the legacy
CodeAnalysis.ruleset to a nested src/.editorconfig.

The .ruleset file no longer reliably enables CA2007 with current
.NET SDKs (CA2007 is disabled by default), so the rule only fired
in CI Release builds and was silently ignored locally in Rider and
`dotnet build`.

Using the modern dotnet_diagnostic.<id>.severity in a nested
editorconfig under /src has two benefits:
- it correctly activates rules that are disabled by default;
- it naturally scopes the rule to library code only — tests,
  samples and benchmarks are unaffected, where awaiting without
  ConfigureAwait is fine and often more readable.

Closes #2308

#skip-changelog

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.13%. Comparing base (a9cb3b2) to head (0b8dba2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5230      +/-   ##
==========================================
+ Coverage   74.12%   74.13%   +0.01%     
==========================================
  Files         508      508              
  Lines       18282    18282              
  Branches     3574     3574              
==========================================
+ Hits        13551    13553       +2     
+ Misses       3861     3860       -1     
+ Partials      870      869       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate CA2007 checking

1 participant